{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<script>
    function no_pic(obj) {
        obj.setAttribute("src", "/Public/Images/acp/nopicture.jpg");
    }
</script>

<div class="tablesWrap">
    <div class="tables-searchbox">
        <form method="post">
            <span class="tbs-txt">孵化器名称：</span>
            <input type="text" name="incubator_name" value="{$incubator_name}">

            <span class="tbs-txt">联系人：</span>
            <input type="text" name="contacts" value="{$contacts}">

            <span class="tbs-txt">联系电话：</span>
            <input type="text" name="contact_number" value="{$contact_number}">

            <select name="order_status" id="order_status">
                <option value="-1">-预约状态-</option>
                {foreach from= $order_status_list item = status key =key}
                <option value="{$key}"{if $key EQ $order_status}selected{/if}>{$status}</option>
                {/foreach}
            </select>

               <!-- <span class="tbs-txt">添加时间：</span>
                <input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker()">
                <span class="tbs-txt">至</span>
                <input type="text" autocomplete="off" class="Wdate" name="end_date" value="{$end_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker()">-->
                <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
        <!--        <button type="button" class="btn" style="background-color:#FF9900;color:#FFF" onclick="sync_item();">同步商品资料</button>-->


        </form>
    </div>
    <!-- end tables-searchbox -->
    <table class="wxtables">
        <colgroup>
            <col width="5%">
            <col width="7%">
            <col width="7%">
            <col width="7%">
            <col width="7%">
            <col width="6%">
            <col width="7%">
            <col width="7%">
            <col width="7%">
            {if $type == 2} <col width="7%">{/if}
            <col width="15%">
        </colgroup>
        <thead>
        <tr>
            <td>选择</td>
            <td>孵化器名</td>
            <td>公司名称</td>
            <td>联系人</td>
            <td>联系电话</td>
            <td>{if $type==1}预约面积{else}工位数量{/if}</td>
            <td>预约时间</td>
            <td>入驻天数</td>
            <td>预约状态</td>
            {if $type == 2}<td>支付状态</td>{/if}
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {foreach from=$incubator_order_list  item=stay }
        <tr>
            <td><input type="checkbox" class="checkbox" value="{$stay.order_id}" name="a[]"></td>
            <td>{$stay.incubator_name}</td>
            <td>{$stay.company_name}</td>
            <td>{$stay.contacts}</td>
            <td>{$stay.contact_number}</td>
            <td>{$stay.station_num}</td>
            <td>{$stay.order_time|date_format:"%Y-%m-%d"}</td>
            <td>{$stay.day_num}</td>
            <td>{$stay.status}</td>
            {if $type == 2}<td>{$stay.state}</td>{/if}
            <td>
                <a href="/AcpIncubatorOrder/{if $type==1}park_{else}zhongchuang_{/if}enter_detail/order_id/{$stay.order_id}" class="btn" title="查看预约详情">查看详情</a>

                <a href="javascript:;" class="btn" onclick="delete_obj({$stay.order_id})">删除</a>
                <!--<a href="/AcpServiceType/edit_service_type/service_type_id/{$type.service_type_id}.html" class="btn" title="查看孵化器">修改状态</a>-->
                {if $stay.prospectus}
                <a href="{$stay.prospectus}" class="btn" >下载企业计划书</a>
                <a href="javascript:;" id="upload-prospectus_{$stay.order_id}" class="btn add_upload" data-order_id="{$stay.order_id}">修改企业计划书</a>
                {else}
                <a href="javascript:;" id="upload-prospectus_{$stay.order_id}" class="btn add_upload" data-order_id="{$stay.order_id}">上传企业计划书</a>
                {/if}

                {if $stay.order_status == 0}
                    <a href="javascript:;" class="btn" onclick="set_state({$stay.order_id}, 1)">通过</a>
                    <a href="javascript:;" class="btn" onclick="set_state({$stay.order_id}, 2)">拒绝</a>
                {/if}
                {if $stay.pay_status == 1}
                <a href="javascript:;" class="btn" onclick="refund({$stay.order_id})">退款</a>
                {/if}
            </td>
        </tr>
        {foreachelse}
        <tr><td colspan="10">没有找到任何记录</td></tr>
        {/foreach}
        </tbody>
    </table>
    <!-- end wxtables -->
    <div class="tables-btmctrl clearfix">
        <div class="fl">
            <a href="javascript:Select()" class="btn btn-blue">全选</a>
            <a href="javascript:Cancel()" class="btn btn-blue">取消</a>
            <a href="javascript:;" class="btn btn-blue " onclick="batch_delete_obj()">删除</a>
        </div>
        <div class="fr">
            <div class="paginate">
                {$page_str}
            </div>
            <!-- end paginate -->
        </div>
    </div>
    <!-- end tables-btmctrl -->
</div>
<!-- end tablesWrap -->
{/block}

{block name="js"}
<script type="text/javascript" src="/Public/Js/front/front_js/ajaxupload.3.5.js"></script>
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__ACPJS__/acp_item.js?version={$version}"></script>
<script src="__ACPJS__/AcpItem/list_item.js?version={$version}"></script>
<script src="__JS__/front/jquery.showLoading.min.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>
<link rel="stylesheet" href="__CSS__/front/showLoading.css?version={$version}">
<script>
//var id = $('.add_upload').data(order_id);
//    console.log(id);
</script>
{literal}
<script>
    $(function () {
        $('.add_upload').each(function () {
            var id;
            var order_id;
            id = $(this).attr('id')
            order_id =$(this).data('order_id');
            add_prospectus(id,order_id)
        })
    })
    function add_prospectus(id,order_id) {
        new AjaxUpload("#"+id, {
            action: "/Acp/uploadFileHandler",
            name: "upfile",
            responseType: "json",
            onSubmit: function(){
                //alert('正在上传');
                //preview处的图片改为loading图片
                /*$('.preview-plan').show();
                 if($("#upload-plan").siblings('.preview-plan').find('img').length>=3){
                 alert("最多上传3张图片");
                 return false;
                 }*/
            },
            onChange: function(file, extension){
                if (extension && /^(doc|docx|pdf)$/.test(extension)) {
                    return true;
                }
                else {
                    alert('暂不支持该文件格式')
                    return false;
                }
            },
            onComplete: function(file, response){
//              console.log(response);
                console.log(file);
                if (response.status === 0) {
                    alert(response.msg);
                    location.reload();
                }
                else if (response.status === 1) {

                    $.ajax({
                        type:'post',
                        url:'/AcpIncubatorOrder/incubator_prospectus',
                        data:{id:order_id,url:response.img_url},
                        success:function (data) {
                            if(data.code==1){
                                alert(data.msg);
                            }else{
                                alert(data.msg);
                            }
                        }
                    })
                }
            }
        });
    }


    function Select(){
        var sel=document.getElementsByName("a[]");
        for(var i=0;i<sel.length;i++){
            sel[i].checked=true;
        }
    }
    //取消全选
    function Cancel(){
        var sel=document.getElementsByName("a[]");
        for(var i=0;i<sel.length;i++){
            sel[i].checked=false;
        }
    }


    var item_name = '{$ITEM_NAME}';
    function delete_obj(obj_id) {
        $.jPops.confirm(
            {
                title: "提示",
                content: "您确定要删除这条数据吗？",
                okBtnTxt: "确定",
                cancelBtnTxt: "取消",
                callback: function (r) {
                    if (r) {
                        $.post('/AcpIncubatorOrder/delete_incubator_order', {"obj_id": obj_id}, function (data, textStatus) {
                            if (data == 'success') {
                                alert('恭喜您，删除成功！');
                                location.reload();
                            }
                            else {
                                alert('对不起，删除失败！');
                            }
                        });
                    }
                    return true;
                }
            });
    }

    function batch_delete_obj() {
        $.jPops.confirm(
            {
                title: "提示",
                content: "您确定要删除这些数据吗？",
                okBtnTxt: "确定",
                cancelBtnTxt: "取消",
                callback: function (r) {
                    if (r) {
                        var obj_ids = '';
                        var count = 0;
                        $('input[name="a[]"]:checked').each(function () {
                            count++;
                            obj_ids += $(this).val() + ',';
                        });

                        if (!count) {
                            alert('对不起，请选择至少一项进行删除！');
                            return;
                        }

                        obj_ids = obj_ids.substr(0, obj_ids.length - 1);

                        $.post('/AcpIncubatorOrder/batch_delete_incubator_order', {"obj_ids": obj_ids}, function (data, textStatus) {
                            if (data == 'success') {
                                alert('恭喜您，删除成功！');
                                location.reload();
                            }
                            else {
                                alert('对不起，删除失败！');
                            }
                        });
                    }
                    return true;
                }
            });
    }

    function set_state(obj_id, is_type) {
        // $.jPops.confirm(
        //     {
        //         title: "提示",
        //         content: "您确定要执行该操作吗？",
        //         okBtnTxt: "确定",
        //         cancelBtnTxt: "取消",
        //         callback: function (r) {
        //             if (r) {
        //                 $.post('/AcpIncubatorOrder/set_state', {"obj_id": obj_id, state:state}, function (data, textStatus) {
        //                     if (data == 'success') {
        //                         alert('恭喜您，操作成功！');
        //                         location.reload();
        //                     }
        //                     else {
        //                         alert('对不起，操作失败！');
        //                     }
        //                 });
        //             }
        //             return true;
        //         }
        //     });
        //     
        //     
        if(is_type == 2){
            var title= '未通过理由'
            var html='';
            var html='<form id="reason_form">' +
                    '<div class="formitems inline">'+
                    '<label class="fi-name"><span class="colorRed">*</span>未通过理由：</label>'+
                    '<div class="form-controls">'+
                    '<textarea name="content" id="content"></textarea><span class="fi-help-text"> </span>'+
                    '</div>' +
                    '<input type="hidden" name="obj_id" value="'+obj_id+'">'+
                    '<input type="hidden" name="state" value="'+is_type+'">'+
                    '<input type="hidden" name="act" value="add">'+
                    '</div>'+
                    '</form>';
        }else if(is_type == 1){
            var title='提示';
            var html ='确定通过审核吗?';
        }

        $.jPops.custom({
            title:title,
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    if(is_type == 1){
                        $.post('/AcpIncubatorOrder/set_state',{obj_id:obj_id,is_type:is_type},function(data)
                        {
                            if (data == 'success')
                            {
                                alert('恭喜您，操作成功！');
                                location.reload();
                            }
                            else
                            {
                                alert('对不起，操作失败！');
                            }
                        })
                    }

                    if(is_type == 2){
                        $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpIncubatorOrder/set_state',$('#reason_form').serialize(),function(data)
                                    {
                                        if (data == 'success')
                                        {
                                            alert('恭喜您，操作成功！');
                                            location.reload();
                                        }
                                        else
                                        {
                                            alert('对不起，操作失败！');
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });
                        //表单验证规则
                        $("#reason_form").validate(
                                {
                                    rules:
                                    {
                                        content:
                                        {
                                            required: true
                                        }
                                    },
                                    messages:
                                    {
                                        content:
                                        {
                                            required: "对不起，请填写不通过审核的理由",
                                        }
                                    },
                                    errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                    success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                                });

                        //模拟提交表单
                        $("#reason_form").submit();
                        return acp.batchDeliverFormStatus;
                    }
                }
                else
                {
                    return true;
                }
            }
        });
    }



    //退款
    function refund(order_id){
        
        $.jPops.confirm(
            {
                title: "提示",
                content: "您确定要执行该操作吗？",
                okBtnTxt: "确定",
                cancelBtnTxt: "取消",
                callback: function (r) {
                    if (r) {
                        $.ajax({
                            url:'/AcpIncubatorOrder/refund',
                            type:'post',
                            data:{order_id:order_id},
                            success:function(r){
                                if(r.code == 0){
                                    alert(r.msg);
                                    location.reload();
                                }else if(r.code == 2){
                                    window.location.href = r.link
                                }else{
                                    alert(r.msg);
                                }
                            }
                        })
                    }
                    return true;
                }
            });
            
            

    }
</script>
{/literal}
{/block}
